package com.ld.control.business.equipment.controller;


import com.ld.control.business.equipment.service.EquipmentDataFieldConfigService;
import com.ld.control.business.equipment.vo.req.EquipmentDataFieldConfigReqVo;
import com.ld.control.business.equipment.vo.resp.EquipmentDataFieldConfigRespVo;
import com.ld.control.business.equipment.vo.resp.EquipmentRespVo;
import com.ld.control.common.PrimaryKeyReqVo;
import com.ld.control.common.ResultResponse;
import com.ld.control.common.vo.GenerateListVo;
import com.ld.control.common.vo.GeneratePageListVo;
import com.ld.control.sysenum.ResultResponseEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangfeng
 * @since 2025-01-09
 */
@Slf4j
@Tag(name = "设备检测结果字段配置相关接口")
@RestController
public class EquipmentDataFieldConfigController {


    @Autowired
    private EquipmentDataFieldConfigService equipmentDataFieldConfigService;

    @GetMapping("/api/centralControl/equipmentDataFieldConfig/getPageList")
    @Operation(summary = "设备检测字段显示列表")
    public ResultResponse<GenerateListVo<EquipmentDataFieldConfigRespVo>> getPageList(
            @Parameter(description = "设备Id") @RequestParam(required = false) Long equipmentId
    ) {
        GenerateListVo<EquipmentDataFieldConfigRespVo> list = equipmentDataFieldConfigService.getList(equipmentId);
        return ResultResponse.success(list);
    }

    @GetMapping("/api/centralControl/equipmentDataFieldConfig/getById")
    @Operation(summary = "详情")
    public ResultResponse<EquipmentDataFieldConfigRespVo> getById(
            @RequestParam Long id
    ) {
        EquipmentDataFieldConfigRespVo equipmentDataFieldConfigRespVo = equipmentDataFieldConfigService.getById(id);
        return ResultResponse.success(equipmentDataFieldConfigRespVo);
    }

    @PostMapping("/api/centralControl/equipmentDataFieldConfig/add")
    @Operation(summary = "添加")
    public ResultResponse<ResultResponseEnum> add(
           @RequestBody EquipmentDataFieldConfigReqVo reqVo
    ) {
        equipmentDataFieldConfigService.add(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/equipmentDataFieldConfig/updateById")
    @Operation(summary = "修改")
    public ResultResponse<ResultResponseEnum> updateById(
            @RequestBody EquipmentDataFieldConfigReqVo reqVo
    ) {
        equipmentDataFieldConfigService.updateById(reqVo);
        return ResultResponse.success();
    }

    @PostMapping("/api/centralControl/equipmentDataFieldConfig/deleteById")
    @Operation(summary = "删除")
    public ResultResponse<ResultResponseEnum> deleteById(
            @RequestBody PrimaryKeyReqVo reqVo
    ) {
        equipmentDataFieldConfigService.deleteById(reqVo.getId());
        return ResultResponse.success();
    }
}

